<?php
use yii\helpers\Url;
use yii\web\View;
// use yii\Web\View;
use app\assets\NewCreativeAsset;
NewCreativeAsset::register($this);
$this->title = $this->context->pageTitle.Yii::$app->params['titleSuffix'];
$this->params['breadcrumbs'] = [
  [
    'label' => \Yii::t('creative', 'Creative'),
    'url' => ['creative-list']
  ],
  \Yii::t('creative', 'New Creative')
];
$jsMsgs = $this->context->loadJsMsgs([
  'creativeForm'
]);
$this->registerJs("VAM.setVar('LANGUAGE_JS', '".$jsMsgs."');", View::POS_HEAD);
?>
<div class="page-header">
  <h1>
    <?=\Yii::t('creative', 'Creative')?>
    <small><?=\Yii::t('creative', 'New Display Creative')?></small>
  </h1>
</div>
<div class="panel panel-default">
  <div class="panel-heading">
    <i class="fa fa-plus-circle"></i>
    <?=\Yii::t('creative', 'New Display Creative')?>
    <ul class="list-unstyled pull-right">
      <li>
        <a href="#">
          <i class="fa fa-chevron-up"></i>
        </a>
      </li>
    </ul>
  </div>
  <div class="panel-body">
    <div class="row">
      <div class="col-sm-8 col-sm-offset-2">
        <form class="form-horizontal" id="data-frm" method="POST" action="<?= Url::to(['creative/new-creative-handle']);?>">
      <input class="hidden" type="text" name="solution_id" value="<?=$solution_id?>">
          <input class="hidden" type="text" name="id" value="">
          <fieldset>
            <legend><?=\Yii::t('creative', 'Creative Info')?></legend>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="creative_name" >
                <em>*</em>
                <?=\Yii::t('creative', 'Creative Name')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="creative_name" type="text" name="name" value="" placeholder="<?=\Yii::t('creative', 'Creative Name')?>">
                <div class="help-block text-error" id="creative_name_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="creative_vocation_large" >
                <em>*</em>
                <?=\Yii::t('creative', 'Vocation')?>：
              </label>
              <div class="col-sm-3">
                <select class="form-control" id="creative_vocation_large" name="parent_category">
                </select>
              </div>
              <div class="col-md-3">
                <select class="form-control" id="creative_vocation_small" name="category">
                </select>
              </div>
            </div>
            <div class="form-group hidden" >
              <label class="col-sm-3 control-label" for="dynamic_creative_flag" >
                <em>*</em>
                <?=\Yii::t('creative', 'Dynamic')?>：
              </label>
              <div class="col-sm-7">
                <label class="radio-inline">
                  <input type="radio" name="is_static" value="1" checked> <?=\Yii::t('creative', 'no')?>
                </label>
                <label class="radio-inline">
                  <input type="radio" name="is_static" value="0"> <?=\Yii::t('creative', 'yes')?>
                </label>
                <div class="help-block"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="impr_monitor_url">
                <?=\Yii::t('creative', 'Show Url')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="impr_monitor_url" type="text" name="show_monitor_url" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="impr_monitor_url_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="landing_page_url">
                <em>*</em>
                <?=\Yii::t('creative', 'Landing Page Url')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="landing_page_url" type="text" name="landing_page" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="landing_page_url_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="click_monitor_url" >
                <?=\Yii::t('creative', 'Click Url')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="click_monitor_url" type="text" name="click_monitor_url" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="click_monitor_url_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="audit_target_url">
                <?=\Yii::t('creative', 'Audit Url')?>：
              </label>
              <div class="col-sm-7">
                <input class="form-control" id="audit_target_url" type="text" name="adomain" value="" placeholder="http(s)://">
                <div class="help-block text-error" id="audit_target_url_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label for="belong_creative" class="col-sm-3 control-label">
                <?=\Yii::t('creative', 'Template')?>：
              </label>
              <div class="col-sm-7">
                <select class="form-control" id="belong_creative" name="template_id" placeholder="<?=\Yii::t('creative', 'Template')?>">
                  <?php 
                    foreach($templates as $template) {
                      $id = $template['id'];
                      $name = $template['name'];
                      echo "<option value='$id'>$name</option>";
                    }
                  ?>
                </select>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="alternative_creative_size">
                <?=\Yii::t('creative', 'Valid Size')?>：
              </label>
              <div class="col-sm-7">
                <p class="form-control-static" id="alternative_creative_size" name="alternative_creative_size">
                <?php 
                  $sizeList = [];
                  foreach ($sizes as $k => $size) {
                    $sizeList[] = $size['width'].'*'.$size['height'];
                  }
                  $sizeList = array_unique($sizeList);
                  sort($sizeList);
                  foreach ($sizeList as $k => $size) {
                    echo $size.',  ';
                    if(($k+1)%9 == 0) echo '</br>';
                  }
                ?>
                </p>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label" for="alternative_creative_size">
                <?=\Yii::t('creative', 'Valid Material Type')?>：
              </label>
              <div class="col-sm-7">
                <p class="form-control-static" id="alternative_creative_size" name="alternative_creative_size">JPG,PNG,GIF,SWF</p>
              </div>
            </div>
            <div class="form-group" id="material_source">
              <label class="col-sm-3 control-label" for="alternative_creative_size">
                <?=\Yii::t('creative', 'Material Source')?>：
              </label>
              <div class="col-sm-7">
                <label class="radio-inline">
                  <input type="radio" name="material_source" value="0" checked><?=\Yii::t('creative', 'Upload Material')?>
                </label>
                <label class="radio-inline">
                  <input type="radio" name="material_source" value="1"><?=\Yii::t('creative', 'Custom Url')?>
                </label>
              </div>
            </div>
            <div id="custom_material_url">
              <div class="form-group">
                <label for="custom-url" class="control-label col-sm-3">
                  <em>*</em>
                  <?=\Yii::t('creative', 'Material Url')?>：
                </label>
                <div class="col-sm-7">
                  <input type="text" id="custom_url" class="form-control" name="custom_url" value="" data-err="custom_url_err">
                  <div class="help-block text-error" id="custom_url_err"></div>
                </div>
              </div>
              <div class="form-group" id="custom_adsize">
                <label class="control-label col-md-3">
                  <em>*</em>
                  <?=\Yii::t('creative', 'Material Size')?>：
                </label>
                <label class="control-label col-md-1 pr0">
                  <em>*</em>
                  <?=\Yii::t('creative', 'Width')?>：
                </label>
                <div class="col-md-2">
                  <input class="form-control" type="text" id="adspace_width" value="" name="width" data-err="width_err">
                  <div class="help-block text-error" id="width_err"></div>
                </div>
                <label class="control-label col-md-1 pr0">
                  <em>*</em>
                  <?=\Yii::t('creative', 'Height')?>：
                </label>
                <div class="col-md-2">
                  <input class="form-control" type="text" id="adspace_height" value="" name="height" data-err="height_err">
                  <div class="help-block text-error" id="height_err"></div>
                </div>
              </div>
              <div class="form-group">
                <label for="material-type" class="col-md-3 control-label">
                  <em>*</em>
                  <?=\Yii::t('creative', 'Material Type')?>：
                </label>
                <div class="col-md-7">
                  <select name="material_type" id="" class="form-control">
                    <option value="JPG">JPG</option>
                    <option value="PNG">PNG</option>
                    <option value="GIF">GIF</option>
                    <option value="SWF">SWF</option>
                  </select>
                </div>
              </div>
            </div>
            <div id="local_upload_material">
              <div class="form-group">
                <label class="col-sm-3 control-label" for="upload_material">
                  <em>*</em>
                  <?=\Yii::t('creative', 'Upload Material')?>：
                </label>
                <div class="col-sm-2 col-sm-offset-6">
                  <button class="btn btn-info" id="upload-material" type="button">
                    <i class="fa fa-upload"></i>
                    <?=\Yii::t('creative', 'Upload')?>
                  </button>
                </div>
                <div class="col-sm-12 mt10 text-center">
                  <div class="creative-preview-wrap">
                  </div>
                  <img class="img-thumbnail creative_material_default" id="creative_material_default" data-src="holder.js/310x260/text:<?=\Yii::t('creative', 'Not upload')?>" alt="<?=\Yii::t('creative', 'Not upload')?>">
                  <input id="upload_material" name="upload_material" type="hidden" value="">
                  <div class="help-block text-error" id="upload_material_err"></div>
                </div>
              </div>
            </div>
          </fieldset>
          <fieldset>
            <div class="form-group">
              <div class="col-sm-offset-3 col-sm-7">
                <div class="btn-form-group pull-right">
                  <input class="operate-type" type="hidden" name="operate_type" value="save">
                  <button type="submit" class="btn btn-primary" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('common', 'Saving')?>..."><?=\Yii::t('common', 'Save')?></button>
                  <a href="<?php echo Url::to(['creative/creative-list']); ?>" class="btn btn-default"><?=\Yii::t('common', 'Back')?></a>
                </div>
              </div>
            </div>
          </fieldset>
        </form>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="upload-material-modal">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title"><?=\Yii::t('creative', 'Upload Material')?></h4>
      </div>
      <div class="modal-body">
        <div class="portlet-content">
          <span class="btn btn-success btn-sm fileinput-button">
            <i class="fa fa-plus"></i>
            <span><?=\Yii::t('creative', 'File')?></span>
            <input id="creative-id" type="hidden" name="creative_id" value="${id}" >
            <!-- The file input field used as target for the file upload widget -->
            <input type="file" multiple="" name="files[]" id="fileupload">
          </span>
          <br>
          <br>
          <!-- The global progress bar -->
          <div class="progress" id="progress">
              <div aria-valuemax="100" aria-valuemin="0" class="progress-bar progress-bar-success progress-bar-striped">0%</div>
          </div>
          <!-- The container for the uploaded files -->
          <div class="files" id="files">
            <table class="table table-striped table-bordered">
              <thead>
                <tr>
                  <th>ID</th>
                  <th><?=\Yii::t('creative', 'File Name')?></th>
                  <th><?=\Yii::t('creative', 'File Size')?>(KB)</th>
                  <th><?=\Yii::t('creative', 'Upload Time')?></th>
                  <th><?=\Yii::t('creative', 'Info')?></th>
                  <th><?=\Yii::t('creative', 'Uploader')?></th>
                </tr>
              </thead>
              <tbody></tbody>
              </table>
            </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal"><?=\Yii::t('common', 'Close')?></button>
        <button type="button" class="btn btn-primary" id="upload-confirm-operate" data-material-id=""><?=\Yii::t('common', 'Sure')?></button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php
  $uploadMaterialUrl = Url::to(['creative/upload-pic']);
  // $uploadMaterialUrl = Yii::getAlias('@web') . '/response/creative/uploadMaterialDataList.php';
  $creativeVocation = $categories;
  $this->registerJs("VAM.setVar('UPLOAD_MATERIAL_URL','$uploadMaterialUrl');", View::POS_HEAD);
  $this->registerJs("VAM.setVar('CREATIVE_VOCATION','$creativeVocation')", View::POS_HEAD);
?>
<script type="text/javascript" >
  requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/site.js"], function(common) {
    requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/creative/newCreative.js"]);
  });
</script>